package com.spring.oaassist.web.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.spring.oaassist.web.service.EzvizService;
import com.spring.oaassist.web.service.OaAssistService;
import com.spring.security.core.annotation.OaUserPermission;
import com.spring.security.web.controller.BaseController;
import com.spring.security.web.model.BaseResult;

/**
 * 摄像头配置
 * @author wjy
 *
 */
@Controller
@RequestMapping(value = "/ezviz")
public class EzvizController extends BaseController{
	
	@Resource EzvizService ezvizService;
	
	
	@OaUserPermission(value="/ezviz/index")
	@RequestMapping(value = "/index")
    public ModelAndView index(HttpServletRequest request){
		return new ModelAndView("main/ezviz/index");
    }
	
	
	@RequestMapping(value = "/queryEzviz")
    @ResponseBody
    public Object queryEzviz(String page,String pageSize,HttpServletRequest request){
//		OaUser oaUser = ShopOaSessionUtil.getOaUser(request);
        Map<String, Object> parm = new HashMap<String, Object>();
        Map<String, Object> retD = new HashMap<String, Object>();
        List<Map<String,Object>> list = ezvizService.queryEzviz(parm);
        if(list==null){
        	list=new ArrayList<Map<String,Object>>();
        }
        retD.put("data", list);
        return retD;
    }
	
	@RequestMapping(value = "/saveEzviz")
    @ResponseBody
    public Object saveEzviz(@RequestBody List<Map<String,Object>> checkedArr,HttpServletRequest request){
		BaseResult retVal = new BaseResult();
//		OaUser oaUser = ShopOaSessionUtil.getOaUser(request);
		try{
			retVal = ezvizService.saveEzviz(checkedArr);
		}catch(Exception e){
			e.printStackTrace();
			retVal.setStatus("0");
			retVal.setMsg("操作失败");
		}
        return retVal;
    }
	
	@RequestMapping(value = "/delEzviz")
    @ResponseBody
    public Object delEzviz(String id,HttpServletRequest request){
		BaseResult retVal = new BaseResult();
//		OaUser oaUser = ShopOaSessionUtil.getOaUser(request);
		try{
			retVal = ezvizService.delEzviz(id);
		}catch(Exception e){
			e.printStackTrace();
			retVal.setStatus("0");
			retVal.setMsg("操作失败");
		}
        return retVal;
    }
	
	
	
	/**
	 * easyui测试
	 */
	@Resource
	private OaAssistService oaAssistService;
	
	@RequestMapping(value = "/protest")
    public ModelAndView protest(HttpServletRequest request){
		return new ModelAndView("main/parkinfo/easyproduct");
    }
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	@RequestMapping(value = "/queryProduct")
    @ResponseBody
    public Object queryProduct(String kids_park_id,String productName,String page,String rows,String sort,String order,HttpServletRequest request){
        Map<String, Object> parm = new HashMap<String, Object>();
        Map<String, Object> retD = new HashMap<String, Object>();
    	parm.put("kids_park_id",kids_park_id);
    	parm.put("productName",productName);
    	System.out.println("--------->"+sort+","+order);
//    	parm.put("kids_park_id", "51c7325f-3c91-484f-85d0-1feecef70116");
    	PageHelper.startPage(Integer.parseInt(page), Integer.parseInt(rows));
        List<Map<String,Object>> list = oaAssistService.queryProduct(parm);
        PageInfo pageObj = new PageInfo(list);
        retD.put("total", pageObj.getTotal());
//        retD.put("total", list.size());
        retD.put("rows", list);
        return retD;
    }



@RequestMapping(value = "/saveProduct")
@ResponseBody
public Object saveProduct(String park_product_id,String businessTypeCode,String name,String proname,String unitPrice){
    Map<String, Object> parm = new HashMap<String, Object>();
    Map<String, Object> retD = new HashMap<String, Object>();
    
    System.out.println(park_product_id+businessTypeCode+name+proname+unitPrice);
    
    return null;
}


@RequestMapping(value = "/deleteProduct")
@ResponseBody
public Object deleteProduct(String park_product_id){
    Map<String, Object> parm = new HashMap<String, Object>();
    Map<String, Object> retD = new HashMap<String, Object>();

    System.out.println(park_product_id);
    
    return null;
}


@RequestMapping(value = "/updateProduct")
@ResponseBody
public Object updateProduct(String park_product_id,String businessTypeCode,String name,String proname,String unitPrice,HttpServletRequest request){
    Map<String, Object> parm = new HashMap<String, Object>();
    Map<String, Object> retD = new HashMap<String, Object>();

    System.out.println(park_product_id+businessTypeCode+name+proname+unitPrice);
    
    return null;
}


}

